package com.example.grpcquick;

import com.example.grpcquick.AddServiceGrpc.AddServiceBlockingStub;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import com.example.grpcquick.AddServiceGrpc;
import com.example.grpcquick.AddRequest;
import com.example.grpcquick.AddReply;

import java.io.IOException;

public class AddClient {
    private ManagedChannel channel;
    private AddServiceBlockingStub stub;

    public AddClient() {
        // channel
        this.channel = ManagedChannelBuilder
                .forAddress("127.0.0.1", 9999)
                // 使用明文传输，否则还需要配置ssl
                .usePlaintext()
                .build();
        // stub桩子，用于传输数据
        this.stub = AddServiceGrpc.newBlockingStub(channel);
    }

    public static void main(String[] args) throws IOException {
        AddClient addClient = new AddClient();
        AddReply reply = addClient.stub.add(AddRequest.newBuilder()
                .setA(5)
                .setB(6)
                .build());
        System.out.println(reply.getRes());
    }
}
